package cn.com.hp.feature.controller;

import cn.com.hp.feature.domain.dto.SysUserInfoDTO;
import cn.com.hp.feature.domain.entity.SysUserInfo;
import cn.com.hp.feature.domain.vo.PageVO;
import cn.com.hp.feature.domain.vo.SysUserInfoVO;
import cn.com.hp.feature.response.BaseResponse;
import cn.com.hp.feature.response.BaseResponseStatus;
import cn.com.hp.feature.service.ISysUserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Condition;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: hjz
 * @since: 2022/8/27
 * @description:
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user")
@Api(value = "系统用户信息", tags = "系统用户信息接口")
public class SysUserInfoController {

    @Autowired
    private ISysUserInfoService sysUserInfoService;

    /**
     * 详情
     */
    @GetMapping("/detail/{userId}")
    @ApiOperation(value = "根据用户id获取详情", notes = "传入user的id")
    public BaseResponse<SysUserInfoVO> detail(@PathVariable String userId) {
        BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.OK);
        SysUserInfo detail = sysUserInfoService.getById(userId);
        baseResponse.setData(detail);
        return baseResponse;
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增(用户信息)", notes = "sysUserInfo")
    public BaseResponse<SysUserInfo> save(@RequestBody SysUserInfo sysUserInfo) {
        BaseResponse baseResponse = new BaseResponse();
        sysUserInfoService.save(sysUserInfo);
        baseResponse.setData(sysUserInfo);
        return baseResponse;
    }



    /**
     * 更新
     */
        @PostMapping("/update/by/{userId}")
    @ApiOperation(value = "更新用户信息", notes = "sysUserInfo")
    public BaseResponse<SysUserInfo> update(@PathVariable String userId,@RequestBody SysUserInfo sysUserInfo) {
        BaseResponse<SysUserInfo> response = new BaseResponse();
        sysUserInfo.setId(userId);
        sysUserInfoService.updateById(sysUserInfo);
        response.setData(sysUserInfo);
        return response;
    }

    /**
     * 根据条件查询用户列表信息list
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表查询", notes = "sysUserInfo")
    public BaseResponse list(SysUserInfo sysUserInfo) {
        BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.OK);
        List<SysUserInfo>  userInfos = sysUserInfoService.selectList(sysUserInfo);
        baseResponse.setData(userInfos);
        return baseResponse;
    }

    /**
     * 条件查询用户信息(分页)
     * @param sysUserInfo
     * @return
     */
    @ApiOperation(value = "分页查询用户基本信息列表", notes = "分页查询用户基本信息列表")
    @ResponseBody
    @GetMapping("/page")
    public BaseResponse<PageVO<SysUserInfo>> selectFormPage(SysUserInfoDTO sysUserInfo) {
        BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.OK);
        PageVO<SysUserInfo> dataList = sysUserInfoService.selectUserPage(sysUserInfo);
        baseResponse.setData(dataList);
        return baseResponse;
    }

}
